package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

import Controler.TestDate;
import Model.Lieu;
import Model.Famille;
import Model.Eleve;

public class Eleve_Modifier{

	public void modifier(Eleve el){
		
		try {

			connexionBDD a = new connexionBDD();
			Connection conn=a.connect();
			Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
			Statement state2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
			Statement state3 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
			
			Lieu l = el.getAdresse_cours();
			Famille f = el.getId_famille();
			
			state.executeUpdate("UPDATE lieu SET numero="+l.numero+", rue='"+l.rue+"', complement='"+l.complement+"', codepostal="+l.cp+", ville='"+l.ville+"' WHERE id_lieu_cours="+l.getIdLieu());
			state.executeUpdate("UPDATE famille SET nom_rep='"+f.nom+"', prenom_rep='"+f.prenom+"', tel_rep="+f.num+", email_rep='"+f.mail+"' WHERE id_famille="+f.getIdFamille());
			Date date =  TestDate.stringToDate("1990-12-11");
			state.executeUpdate("UPDATE eleve SET nom_eleve='"+el.nom+"', prenom_eleve='"+el.prenom+"', sexe_ele='"+el.sexe+"', date_naiss_ele='08-Jan-1979', mail_ele='"+el.email+"', tel_ele="+el.tel+" WHERE id_eleve="+el.getIdEleve());
			System.out.println("Modification eleve reussie");
			
			state.close();
			state2.close();
			state3.close();
			
		} 

		catch (Exception e) {
			e.printStackTrace();
		}

	}

}